<script>
    function updateQueryStringParam(uri, key, value = null) {
        return (function handler(uri, key, value) {
            if (uri.length) {
                if (typeof key == "string") {
                    if (value !== null) {
                        const re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
                        let separator = uri.indexOf("?") !== -1 ? "&" : "?";
                        if (uri.match(re)) {
                            return uri.replace(re, "$1" + key + "=" + value + "$2");
                        } else {
                            return uri + separator + key + "=" + value;
                        }
                    }
                } else if (typeof key == "object") {
                    for (let k in key) {
                        uri = handler(uri, k, key[k])
                    }
                }
            }
            return uri;
        }(uri, key, value))
    }
    // 全局混入事件
    Vue.mixin({
        methods: {
            export(table) {
                console.log(table.getSearchParams())

                let requestParams = table.getSearchParams();

                let values = "";
                for (var param in requestParams){
                    if (values) values += '&';
                    let _param = requestParams[param];
                    if (_param instanceof Array){
                        for (i in _param) {
                            console.log("value",_param[i]);
                            var data = (new Date(_param[i]));
                            if(data.getFullYear()) {

                                _param[i] = data.getFullYear() + "-" + (data.getMonth() + 1) + "-" + data.getDate() + " " + data.getHours() + ":" + data.getMinutes() + ":" + data.getSeconds();

                            }
                        }
                    }
                    values += param + '=' + _param;
                }
                if (values){

                    export_url += export_url.indexOf("?") !== -1 ? '&' : '?'
                    export_url += values
                }
                let that = this
                let _axios = typeof window !== 'undefined' && window.axios ? window.axios : axios;
                let config = Object();
                config.url = export_url;
                config.method = 'post';
                const loading = this.$loading({
                    lock: true,
                    text:"请稍候…",
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.1)'
                });
                _axios(config).then(function (res){
                    loading.close();
                    if (res.data.code == 0){

                        LAY_EXCEL.exportExcel(res.data.data.list, res.data.data.title + '表格导出.xlsx', 'xlsx')
                    }else{
                        that.$message.error("获取导出数据失败")
                    }
                }).catch(res => {
                    that.$message.error("数据异常")
                    loading.close();
                })

            },
            extendTableData(table , data){
                if (data.stat){
                    let statistics = document.getElementsByClassName('statistics')
                    statistics[0].innerHTML = data.stat;
                }
            },
        }
    })
</script>